package com.heartech.prediciton_wx.controller.wxparameter;


import com.heartech.prediciton_wx.constant.WxCode;
import com.heartech.prediciton_wx.entity.qrcode.QrTicket;
import com.heartech.prediciton_wx.entity.token.AccessToken;
import com.heartech.prediciton_wx.service.token.TicketService;
import com.heartech.prediciton_wx.service.token.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

@Slf4j
@RestController
@RequestMapping("/wxpublic")
public class TicketController {

    @Autowired
    private TicketService ticketService;
    @PostMapping("/ticket/")
    public ResponseEntity<QrTicket> getTicket(@RequestParam String access_token) {
        String url = WxCode.get_ticket;
        QrTicket response = ticketService.getTicket(url, access_token);

        if (response != null) {
            return ResponseEntity.ok(response);
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }
}
